<?php

namespace app\common\model;

use think\Model;
use traits\model\SoftDelete;

class School extends Model
{
    //软删除
    use SoftDelete;

    //合作伙伴添加
    public function school_add($data)
    {
        $validate = new \app\common\validate\School();
        if (!$validate -> check($data)){
            return $validate -> getError();
        }
        $result = $this -> save($data);
        if ($result){
            return 1;
        } else {
            return '添加失败！';
        }
    }

    //合作伙伴编辑
    public function school_edit($data)
    {
        $validate = new \app\common\validate\School();
        if (!$validate->check($data)){
            return $validate -> getError();
        }
        $school = $this -> find($data['id']);
        $school -> region = $data['region'];
        $school -> cname = $data['cname'];
        $school -> jname = $data['jname'];
        $result = $school -> save();
        if ($result){
            return 1;
        } else {
            return '更新成功！';
        }
    }

    //合作伙伴状态控制
    public function school_status($data)
    {
        $schoolInfo = $this -> find($data['id']);
        $schoolInfo -> status = $data['status']?0:1;
        $result = $schoolInfo -> save();
        if ($result){
            return 1;
        } else {
            return '操作失败！';
        }
    }

}
